﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;

namespace HQWeb.View
{
    /// <summary>
    /// GetDetialTheme 的摘要说明
    /// </summary>
    public class GetDetialTheme : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string strProjectID = context.Request["id"];
            context.Response.Write(strGetResout(strProjectID));
        }
        private string strGetResout(string strProjectID)
        {
            StringBuilder strHtml = new StringBuilder();
            Model.SysManage.T_PUB_WEDDINGTHEME model = new Model.SysManage.T_PUB_WEDDINGTHEME();
            BLL.SysManage.T_PUB_WEDDINGTHEME bll = new BLL.SysManage.T_PUB_WEDDINGTHEME();
            model = bll.GetModel(strProjectID);
            if (model != null)
            {
                strHtml.Append("<table width=\"100%\"> ");

                strHtml.Append("<tr> <td align=\"right\" style=\"width: 30%\">");
                strHtml.Append("庆典名称：</td>");

                strHtml.Append(string.Format("<td align=\"left\">{0}</td> </tr>", model.TITLE));
                strHtml.Append("<tr> <td align=\"right\">庆典类型： </td>");

                string strTemp = "";
                BLL.SysManage.T_PUB_DICTIONARY dbll = new BLL.SysManage.T_PUB_DICTIONARY();
                List<Model.SysManage.T_PUB_DICTIONARY> il = dbll.GetListArray(" FLAG = 1 order by ORDER_ID ");
                Model.SysManage.T_PUB_DICTIONARY tempMode;
                tempMode = il.Find(p => p.ID.ToString() == model.Type); //庆典类型
                if (tempMode != null)
                {
                    strTemp = tempMode.NAME;
                }

                strHtml.Append(string.Format(" <td align=\"left\"> {0}</td></tr>", strTemp));
                strHtml.Append(" <tr>  <td align=\"right\"> 庆典风格：</td>");
                strTemp = "";
                string strID = "";
                string strinIDs = model.WEDDING_STYLE + ",";
                if (strinIDs != "")
                {
                    foreach (Model.SysManage.T_PUB_DICTIONARY item in il)
                    {
                        strID = item.ID + ",";
                        if (strinIDs.IndexOf(strID) >= 0)
                        {
                            strTemp = strTemp + item.NAME + ",";
                        }
                    }
                }
                if (strTemp.IndexOf(",") >= 0)
                {
                    strTemp = strTemp.Substring(0, strTemp.Length - 1);
                }
                strHtml.Append(string.Format("<td align=\"left\"> {0}</td> </tr>", strTemp));
                strTemp = "";

                strHtml.Append(" <tr> <td align=\"right\"> 庆典色彩：</td>");
                tempMode = il.Find(p => p.ID.ToString() == model.WEDDING_COLOR); //色彩
                if (tempMode != null)
                {
                    strTemp = tempMode.NAME;
                }
                strHtml.Append(string.Format("<td align=\"left\"> {0}</td> </tr>", strTemp));
                strTemp = "";
                strHtml.Append("<tr>  <td align=\"right\"> 庆典描述： </td>");
                strHtml.Append(string.Format("<td align=\"left\"> {0}</td> </tr>", model.DESCRIPTION));
                strHtml.Append("<td colspan=\"2\"> 包含项目  </td></tr>");

                strHtml.Append("  <tr> <td colspan=\"2\"> <table width=\"100%\">");

                strHtml.Append("  <tr><th>  序号</th><th> 项目名称</th><th> 单价 </th><th> 数量  </th> </tr>");

                BLL.SysManage.THEME_PROJECT pjbll = new BLL.SysManage.THEME_PROJECT();
                List<Model.SysManage.THEME_PROJECT> projectList = pjbll.GetProjecList(strProjectID);
                int index = 1;
                decimal sum=0;
                foreach (Model.SysManage.THEME_PROJECT item in projectList)
                {
                    strHtml.Append(string.Format("  <tr><td align=\"center\"> {0}</td><td align=\"center\"> {1}</td><td align=\"center\"> {2} </td><td align=\"center\"> {3}  </td> </tr>", index, item.PROJECT_NAME, item.Number, item.PRICE));
                    index = index + 1;
                    if (item.PRICE!=null&&item.Number!=null)
                    {
                        sum=sum+Convert.ToDecimal(item.PRICE*item.Number);
                    }
                }
                strHtml.Append(string.Format("<Tr><td>合计：</td><td colspan=\"3\">{0}</td></tr> ", sum));
                strHtml.Append("   </table> </td> </tr></table>");

            }
            return strHtml.ToString(); ;
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}